//
//  two_sum.hpp
//  cpp_algorithm
//
//  Created by 李贺 on 2021/12/8.
//

#ifndef two_sum_hpp
#define two_sum_hpp

#include <stdio.h>
#include <vector>
#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;

class Solution_two_sum {
    
public:
    
    vector<int> twoSum(vector<int> &nums, int target) {
        
        unordered_map<int, int> map;
        for (int i = 0; i < nums.size(); i++) {
            int dea = target - nums[i];
            auto itor = map.find(dea);
            if ( itor != map.end()) {
                return {itor->second, i};
            }
            map.insert(pair<int, int>(nums[i],i));
        }
        
        return {};
    }
    
};

#endif /* two_sum_hpp */
